package com.muyu.danmo.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoAnnouncement;
import com.muyu.danmo.service.IDanmoAnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 广告Controller
 *
 * @author yangle
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/announcement")
public class DanmoAnnouncementController extends BaseController
{
    @Autowired
    private IDanmoAnnouncementService danmoAnnouncementService;

    /**
     * 查询广告列表
     */
//    @RequiresPermissions("system:announcement:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoAnnouncement danmoAnnouncement)
    {
        PageHelper.startPage(danmoAnnouncement.getPageNum(),danmoAnnouncement.getPageSize());
        List<DanmoAnnouncement> list = danmoAnnouncementService.selectDanmoAnnouncementList(danmoAnnouncement);
        PageInfo<DanmoAnnouncement> danmoAnnouncementPageInfo = new PageInfo<>(list);
        return Result.success(danmoAnnouncementPageInfo);
    }

    /**
     * 导出广告列表
     */
//    @RequiresPermissions("system:announcement:export")
    @Log(title = "广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoAnnouncement danmoAnnouncement)
    {
        List<DanmoAnnouncement> list = danmoAnnouncementService.selectDanmoAnnouncementList(danmoAnnouncement);
        ExcelUtil<DanmoAnnouncement> util = new ExcelUtil<DanmoAnnouncement>(DanmoAnnouncement.class);
        util.exportExcel(response, list, "广告数据");
    }

    /**
     * 获取广告详细信息
     */
//    @RequiresPermissions("system:announcement:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoAnnouncementService.selectDanmoAnnouncementById(id));
    }

    /**
     * 新增广告
     */
//    @RequiresPermissions("system:announcement:add")
    @Log(title = "广告", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoAnnouncement danmoAnnouncement)
    {
        return toAjax(danmoAnnouncementService.insertDanmoAnnouncement(danmoAnnouncement));
    }

    /**
     * 修改广告
     */
//    @RequiresPermissions("system:announcement:edit")
    @Log(title = "广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoAnnouncement danmoAnnouncement)
    {
        return toAjax(danmoAnnouncementService.updateDanmoAnnouncement(danmoAnnouncement));
    }

    /**
     * 删除广告
     */
//    @RequiresPermissions("system:announcement:remove")
    @Log(title = "广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoAnnouncementService.deleteDanmoAnnouncementByIds(ids));
    }
}
